﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Microsoft.Win32;
using System.Windows.Forms;
using EffectMapStudio.Properties;

namespace EffectMapStudio
{
    public partial class Settings : Window
    {
        public Settings()
        {
            InitializeComponent();
            _absolutePath.Text = EffectMapStudio.Properties.Settings.Default.RootPath;
            _contentRoot.Text = EffectMapStudio.Properties.Settings.Default.ContentRoot;
        }

        private void OnOkClick(object sender, RoutedEventArgs e)
        {
            EffectMapStudio.Properties.Settings.Default.ContentRoot = _contentRoot.Text;
            EffectMapStudio.Properties.Settings.Default.RootPath = _absolutePath.Text;
            EffectMapStudio.Properties.Settings.Default.Save();
            DialogResult = true;
        }

        private void OnSelectClick(object sender, RoutedEventArgs e)
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();

            if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                int startIndex = fbd.SelectedPath.LastIndexOf('\\') + 1;
                int length = fbd.SelectedPath.Length - startIndex;
                _absolutePath.Text = fbd.SelectedPath.Substring(0, startIndex - 1);
                _contentRoot.Text = fbd.SelectedPath.Substring(startIndex, length);
            }
        }
    }
}
